package com.escool.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.escool.model.TbGrado;
import com.escool.model.TbNivel;

import com.escool.model.TbMatricula;


import com.escool.service.CatEventoService;
import com.escool.service.CatMatriculaService;
import com.escool.service.GradosService;
import com.escool.service.NivelesService;
import com.escool.service.RolService;

@Controller
public class CatMatriculaController {
	
	@Autowired
	CatMatriculaService CatMatriculaService;

	
	@RequestMapping("showCatMatricula")
	public String showCatMatricula(Map<String, Object> map){
		map.put("CatMatricula", new TbMatricula());
		map.put("TbMatriculaList", CatMatriculaService.listTbMatricula());
		return "/catMatricula";
	}
	
	@RequestMapping(value = "addCatMatricula", method = RequestMethod.POST)
	public String addRoles(@ModelAttribute("CatMatricula") @Valid TbMatricula tbCatMatricula, BindingResult result){
		if (!result.hasErrors()) {
			CatMatriculaService.addTbMatricula(tbCatMatricula);
			return "redirect:/showCatMatricula";
		}
		return "";
	}
	
	@RequestMapping(value = "editCatMatricula", method = RequestMethod.POST)
	public String editRoles(@ModelAttribute("CatMatricula") @Valid TbMatricula tbCatMatricula, BindingResult result){
		if (!result.hasErrors()) {
			CatMatriculaService.editTbMatricula(tbCatMatricula);
			return "redirect:/showCatMatricula";
		}
		return "";
	}
	
	@RequestMapping(value = "deleteCatMatricula", method = RequestMethod.POST)
	public String delRoles(@ModelAttribute("CatMatricula") @Valid TbMatricula tbCatMatricula, BindingResult result){
		if (!result.hasErrors()) {
			CatMatriculaService.delTbMatricula(tbCatMatricula.getIdMatricula());
			return "redirect:/showCatMatricula";
		}
		return "";
	}

}
